<#
    .AUTHOR
        cw50406@imcnam.ssmb.com  
    .GROUP
        RPA AA STE Support Team(dl.gt.cn.cstc.rpa.aa.ste@imcnam.ssmb.com)
    .VERSION
        3.0
    .Synopsis
        Control Room Website Auto Login trigger
    .DESCRIPTION
        This script is used to trigger WebsiteAutoLogin.ps1 by specified different urls
    .EXAMPLE
        .\CRWebsiteLogin.ps1
#>
[CmdletBinding()]param(
    [Parameter(Mandatory=$False)]
    [string]$web_login_user='nam\aaadmin',
    [string]$web_login_user_pwd,
    [string]$logfile
)
ps notepad,iexplore -ea 0|kill -force -ea 0
$this_path = Split-Path -Parent ($MyInvocation.MyCommand.Definition)                      #<-------- this script running directory
Move-Item "C:\reconnect_disconnected_vdi\reconnect_disconnected_vdi_main_script.bat" "$this_path\" -force 1>$null 2>&1 
. "$this_path\functions.ps1"                                                              #<-------- initilize parames, functions & .NET assembles
If( $PSBoundParameters.ContainsKey('logfile' ) ){
    $log_file=$logfile
}else{Write-Log Normal "----------------------------START OF SCRIPT----------------------------" $log_file}
Pop-Message $this_user                                                                               #<------ notify user not take action during runnin time
If( !$PSBoundParameters.ContainsKey('web_login_user_pwd' ) ){$web_login_user_pwd=$this_user_pwd}
If( "$this_domain$this_env$this_node" -imatch 'namuat2|namdev1|eurprod1' ){                   #<------ only check load blance part for specified env
    . "$this_path\WebsiteAutoLogin.ps1" $cr_lb_url "cr-lb" 'Repository Manager' $web_login_user $web_login_user_pwd $log_file 3 -FunctionInvoked
    . "$this_path\WebsiteAutoLogin.ps1" $cr_vault_status_lb_url "vs-lb" '"Status":"Opened"' $web_login_user $web_login_user_pwd $log_file 4 -FunctionInvoked
}
. "$this_path\WebsiteAutoLogin.ps1" $cr_url "cr" 'Repository Manager' $web_login_user $web_login_user_pwd $log_file 1 -FunctionInvoked 
. "$this_path\WebsiteAutoLogin.ps1" $cr_vault_status_url "vs" '"Status":"Opened"' $web_login_user $web_login_user_pwd $log_file 2 -FunctionInvoked -sendEmail
Pop-Message $this_user "Script finishes.(this window will disappear in 10s)"                         
Move-Item "$this_path\reconnect_disconnected_vdi_main_script.bat" "C:\reconnect_disconnected_vdi\" -force 1>$null 2>&1 
